package com.lujianfei.shortcut

import android.content.Intent
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager


/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ShortCutUtilsTest {

    companion object {
        private const val TAG = "ShortCutUtilsTest"
    }

    @Test
    fun addShortCutTest() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("com.lujianfei.shortcut", appContext.packageName)
        ShortCutUtils.addShortCut(appContext, shortLabel = "AddShortCut", id = "id", packageName = "com.android.settings")
    }

    @Test
    fun isShortCutExistTest() {
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        val shortCutExist = ShortCutUtils.isShortCutExist(appContext, id = "id")
        Log.d(TAG, "isShortCutExistTest $shortCutExist")
    }

    @Test
    fun checkSelfShortPermission() {
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        val permission = Settings.Secure.getString(appContext.contentResolver, "launcher_shortcut_permission_settings");
        Log.d(TAG, "checkSelfShortPermission $permission")
    }

    @Test
    fun showToast() {
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        Toast.makeText(appContext,"nima", Toast.LENGTH_SHORT).show()
    }

    @Test
    fun shortCutList(){
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        val shortcutManager = appContext.getSystemService(ShortcutManager::class.java)
        val shortcutInfoList = shortcutManager.pinnedShortcuts
        shortcutInfoList.forEach {
            Log.d(TAG,"shortcutInfoList  id=${it.id}")
        }
    }
}
